home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / wnos / wn941101 / arpfconv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-10  |  2.7 KB  |  97 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "global.h"
  4.  
  5. #define ARP_FILE_VERSION    3
  6. #define NHWTYPES            9
  7.  
  8. char arp_filename[] = "arproute.dat";
  9. char arp_tmpfilename[] = "arproute.tmp";
  10.  
  11. struct arp_saverecord {
  12.   int32 ip_addr;          /* IP address, host order */
  13.   int16 hardware;         /* Hardware type */
  14.   int16 hwalen;           /* Length of hardware address */
  15.   char  pub;              /* Publish this entry? */
  16. };
  17. struct arp_saverecord3 {
  18.   int32 ip_addr;          /* IP address, host order */
  19.   int16 hardware;         /* Hardware type */
  20.   int    flags;              /* AX.25 connection type */
  21.   int16 hwalen;           /* Length of hardware address */
  22.   char  pub;              /* Publish this entry? */
  23. };
  24.  
  25. main ()
  26. {
  27.  
  28.   FILE *fp, *fp1;
  29.   char  hw_addr[255];
  30.   struct arp_saverecord  buf;
  31.   struct arp_saverecord3 buf3;
  32.   int version;
  33.  
  34.   printf("ARPFCONV.EXE - Copyright by DB3FL\n");
  35.   printf("Konvertiert das 'arproute.dat' File von WNOS.2x zu WNOS.3A und höher\n");
  36.   printf("Achtung! Das konvertierte File kann von WNOS.2x nicht mehr verarbeitet werden\n");
  37.   printf("Converts 'arproute.dat' file from WNOS.2x to WNOS.3A and up\n");
  38.   printf("Attention! The converted file is no longer readable by WNOS.2x\n\n");
  39.  
  40.   if ((fp = fopen(arp_filename,READ_BINARY)) == NULLFILE) {
  41.     printf("'%s' muss im selben Verzeichnis sein\n",arp_filename);
  42.     printf("'%s' must be in the same directory\n",arp_filename);
  43.     exit(1);
  44.   }
  45.   version = getc(fp);
  46.  
  47.   if(version != 0 && version != 3) {
  48.     printf("Falsches Fileformat\n");
  49.     printf("Incorrect fileformat\n");
  50.     fclose(fp);
  51.     exit(1);
  52.   }
  53.   if(version == 3) {
  54.     printf("File bereits konvertiert\n");
  55.     printf("File already converted\n");
  56.     fclose(fp);
  57.     exit(1);
  58.   }
  59.  
  60.  
  61.   if ((fp1 = fopen(arp_tmpfilename,WRITE_BINARY)) == NULLFILE) {
  62.     printf("Fehler beim Schreiben von '%s'\n",arp_tmpfilename);
  63.     printf("Error on writing '%s'\n",arp_tmpfilename);
  64.     fclose(fp);
  65.     exit(1);
  66.   }
  67.   putc(ARP_FILE_VERSION,fp1);
  68.  
  69.   while (fread((char *) & buf, sizeof(buf), 1, fp))
  70.     if (fread(hw_addr, buf.hwalen, 1, fp))
  71.       if (buf.hardware < NHWTYPES) {
  72.         buf3.ip_addr = buf.ip_addr;
  73.         buf3.hardware = buf.hardware;
  74.         buf3.flags = 0;        /* here is the difference! */
  75.         buf3.hwalen = buf.hwalen;
  76.         buf3.pub = buf.pub;
  77.         fwrite((char *) & buf3, sizeof(buf3), 1, fp1);
  78.         fwrite(hw_addr, buf3.hwalen, 1, fp1);
  79.       }
  80.  
  81.   fclose(fp);
  82.   fclose(fp1);
  83.  
  84.   unlink("arproute.bak");
  85.   rename(arp_filename,"arproute.bak");
  86.   unlink(arp_filename);
  87.   rename(arp_tmpfilename,arp_filename);
  88.  
  89.   printf("'%s' gesichert als 'arproute.bak'\n",arp_filename);
  90.   printf("'%s' saved as 'arproute.bak'\n\n",arp_filename);
  91.   printf("Konvertierung beendet\n");
  92.   printf("Conversion finished\n");
  93.   exit(0);
  94.   return;
  95. }
  96.  
  97.